package com.ruoyi.tranShort.controller;

import java.util.List;

import com.ruoyi.tranShort.domain.ShortMqttConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tranShort.domain.ShortSerialPortConfig;
import com.ruoyi.tranShort.service.IShortSerialPortConfigService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 串口配置Controller
 * 
 * @author ruoyi
 * @date 2021-08-14
 */
@Api("串口配置")
@RestController
@RequestMapping("/tranShort/serialPorttConfig")
public class ShortSerialPortConfigController extends BaseController
{
    @Autowired
    private IShortSerialPortConfigService shortSerialPortConfigService;

    /**
     * 获取串口配置详细信息
     */
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo()
    {
        return AjaxResult.success(shortSerialPortConfigService.selectShortSerialPortConfig());
    }



    /**
     * 修改mqtt配置
     */
    @Log(title = "连接串口", businessType = BusinessType.UPDATE)
    @ApiOperation("串口连接")
    @PostMapping("/connect")
    public AjaxResult connect(@RequestBody ShortSerialPortConfig shortSerialPortConfig)
    {
        return toAjax(shortSerialPortConfigService.updateShortSerialPortConfig(shortSerialPortConfig));
    }

    /**
     * 获取串口列表
     * @return
     */
    @ApiOperation("获取串口列表")
    @GetMapping("/getPortAll")
    public AjaxResult getPortAll(){
        return shortSerialPortConfigService.getPortAll();
    }

    /**
     * 关闭串口
     * @return
     */
    @ApiOperation("关闭串口")
    @GetMapping("/close")
    public AjaxResult close(){
        return shortSerialPortConfigService.close();
    }
}
